/* Author:

*/

 $(document).ready(function() {
	 
	 var winH = $(window).height();
	 
	 $("#page3").live("pageshow",function(){
			$(window).resize(function(){
				$("#map_canvas3").css('height',winH);
				
			});	
			 $("#map_canvas3").css('height',winH);
			 
			 initializeMapBikes();
			 
	 });
  });

	
 
	
	
	
	
	
	function initializeMapBikes() {
		
		  var myLatLng = new google.maps.LatLng(45.464683238625966, 9.18879747390747);
		  		  
		  
		  
		  var myOptions = {
		    zoom: 13,
		    center: myLatLng,
		    disableDefaultUI: true,
		    mapTypeId: google.maps.MapTypeId.ROADMAP
		  };

		  var map = new google.maps.Map(document.getElementById("map_canvas3"), myOptions);	
		  
		  if(navigator.geolocation) {
			    navigator.geolocation.getCurrentPosition(function(position) {

			    myLatLng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
			      var placeMarker = new google.maps.Marker({
			        position: myLatLng,
			        map: map,
			      });
			      map.setCenter(myLatLng);
			    }, function() {			    	
			        map.setCenter(myLatLng);

			    });
		  }		

		  
		  
			$.get('dati/bikes.kml', function(xml){
				var json = $.xml2json(xml);	
				
				$.each( json.Document.Placemark, function(i, marker) {

					var coordinates = marker.Point.coordinates.split(',');
					
					var infowindow = new google.maps.InfoWindow({
						content:  marker.description + '<br /><a style="margin-left:5px;float:left;font:bold 11px verdana" href="http://maps.google.com/maps?q='+coordinates[1]+','+coordinates[0]+'" target="_blank">View in Google Maps</a>'
					});
					
					
					
					  var marker = new google.maps.Marker({
					      position: new google.maps.LatLng(coordinates[1], coordinates[0]),
					      map: map,
					      icon: new google.maps.MarkerImage('img/map/bicycle_shop.png')
					  });
					  
					  google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); });

				});					
				
				
			
			 }); 
			
		/*
		
		$.get('dati/ostelli.xml', function(xml){
			var json = $.xml2json(xml);

			
			$.each( json.row.row, function(i, marker) {

				var contentString = '<div id="tooltip">'+
				'<img src="img/map/bed_breakfast1-2.png">'+
		  		'<p><strong>'+marker.denominazione+'</strong><br>'+
				'indirizzo: '+marker.indirizzo+', '+marker.comune_provincia+'<br />'+
			    'telefono: '+marker.telefono+'<br />'+
			    'numero posti letto: '+marker.numero_posti_letto+'<br />'+
			    'sito internet: <a href="http://'+marker.sito_internet+'" target="_blank">'+marker.sito_internet+'</a><br />'+
		  		'<br /></p>'+
		  		'<br /></div>';				
				
				
				var infowindow = new google.maps.InfoWindow({
					content:  contentString
				});
				
				
				
				
				  var marker = new google.maps.Marker({
				      position: new google.maps.LatLng(marker.lat, marker.lng),
				      map: map,
				      title: marker.denominazione,
				      icon: new google.maps.MarkerImage('img/map/bed_breakfast1-2.png')
				  });
				  
				  google.maps.event.addListener(marker, 'click', function() {
					  
					  
					  
					  infowindow.open(map,marker);
					  
					  
					});

			});			
			
			
		});		
		
		*/
		
		
		
//		$.getJSON( 'dati/rows.json', function(data) { 
//			
//			
//
//		});			
		

		}

	
	
	
	
	